
class Singleton(type):
    """Singleton Metaclass"""

    def __init__(cls, name, bases, dic):
        super(Singleton, cls).__init__(name, bases, dic)
        cls.instance = None

    def __call__(cls, *args, **kwargs):
        if cls.instance is None:
            cls.instance = super(Singleton, cls).__call__(*args, **kwargs)
        return cls.instance


class BaseOsmpRPC(object):
    
    def __init__(self, mods):
        self.methods = []
        for name in mods:
            modname = 'mod_' + name
            mod = __import__(modname)
            clazz = getattr(mod, name)
            instance = clazz()
            setattr(self, name, instance)
            self.methods += [name + '.' + member
                for member in instance.PUBLIC_METHODS]
        self.methods.sort()




    def listMethods(self):
        return self.methods


